package com.ruoyi.business.service.impl;

import com.ruoyi.business.domain.Shop;
import com.ruoyi.business.mapper.ShopMapper;
import com.ruoyi.business.service.IShopService;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * 店铺信息管理Service业务层处理
 *
 * @author dxw
 * @date 2024-09-12
 */
@Service
public class ShopServiceImpl implements IShopService
{
    @Autowired
    private ShopMapper shopMapper;

    /**
     * 查询店铺信息管理
     *
     * @param id 店铺信息管理主键
     * @return 店铺信息管理
     */
    @Override
    public Shop selectShopById(Long id)
    {
        return shopMapper.selectShopById(id);
    }

    /**
     * 查询店铺信息管理列表
     *
     * @param shop 店铺信息管理
     * @return 店铺信息管理
     */
    @Override
    public List<Shop> selectShopList(Shop shop)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Set<String> roles = loginUser.getRoles();

        if (roles.contains("business")&&!SecurityUtils.isAdmin(loginUser.getUserid())) {
            shop.setMobile(loginUser.getUsername());
            return shopMapper.selectShopList(shop);
        }

        return shopMapper.selectShopList(shop);
    }

    @Override
    public List<Shop> selectShopByServiceId(Long serviceId) {
        return shopMapper.selectShopByServiceId(serviceId);
    }

    /**
     * 新增店铺信息管理
     *
     * @param shop 店铺信息管理
     * @return 结果
     */
    @Override
    public int insertShop(Shop shop)
    {
        return shopMapper.insertShop(shop);
    }

    /**
     * 修改店铺信息管理
     *
     * @param shop 店铺信息管理
     * @return 结果
     */
    @Override
    public int updateShop(Shop shop)
    {
        shop.setUpdateTime(DateUtils.getNowDate());
        return shopMapper.updateShop(shop);
    }

    /**
     * 批量删除店铺信息管理
     *
     * @param ids 需要删除的店铺信息管理主键
     * @return 结果
     */
    @Override
    public int deleteShopByIds(Long[] ids)
    {
        return shopMapper.deleteShopByIds(ids);
    }

    /**
     * 删除店铺信息管理信息
     *
     * @param id 店铺信息管理主键
     * @return 结果
     */
    @Override
    public int deleteShopById(Long id)
    {
        return shopMapper.deleteShopById(id);
    }
}
